package com.qfedu.fmmall.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * 数据库公共字段自动填充
 */
@Component
public class MybatisObjectHandler implements MetaObjectHandler {
    public static void main(String[] args) {


    }
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("userRegtime", LocalDateTime.now(),metaObject);
        this.setFieldValByName("userModtime", LocalDateTime.now(),metaObject);
        this.setFieldValByName("userImg","D:\\javawenjian2\\dnsc-preant\\dnsc-api\\src\\main\\resources\\img\\阿离.jpg",metaObject);
        this.setFieldValByName("createTime",LocalDateTime.now(), metaObject);
        this.setFieldValByName("updateTime", LocalDateTime.now(),metaObject);
        this.setFieldValByName("cartTime", new Date().toLocaleString(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("userModtime", LocalDateTime.now(),metaObject);
        this.setFieldValByName("updateTime", LocalDateTime.now(),metaObject);
        this.setFieldValByName("cartTime", new Date().toLocaleString(),metaObject);
    }
}
